package com.younio.local.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Qn {

    private String name;

    private BigDecimal val;

    private String value;

    private boolean init;

    public BigDecimal getVal() {
        this.val = this.val == null ? BigDecimal.ZERO : val;
        return val;
    }

    public void init(int scale, int digit) {
        if (init) {
            return;
        }
        value = name.replace("Q", "");

        int tmp = 1;
        for (int i = 0; i < digit - 1; i++) {
            tmp *= 10;
        }
        for (int i = 0; i < scale; i++) {
            val = val.multiply(BigDecimal.TEN);
        }
        int v = val.abs().intValue();
        if (v > tmp) {
            v = tmp - 1;
        }


        value = Integer.parseInt(value) * tmp + v + "";
        init = true;
    }


}
